package com.lengyu.vxminiprogram.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lengyu.vxminiprogram.common.HttpResultDto;
import com.lengyu.vxminiprogram.convert.IGameInstanceConverter;
import com.lengyu.vxminiprogram.dto.GameInstanceDto;
import com.lengyu.vxminiprogram.dto.InstanceMonsterDto;
import com.lengyu.vxminiprogram.dto.VotesDto;
import com.lengyu.vxminiprogram.entity.GameInstance;
import com.lengyu.vxminiprogram.service.IGameInstanceService;
import com.lengyu.vxminiprogram.service.IInstanceMonsterService;
import com.lengyu.vxminiprogram.service.IInstanceMonsterSkillService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuyu
 * @since 2025-03-05
 */
@RestController
@RequestMapping("/game-instance")
public class GameInstanceController {
    private final static Logger logger = LoggerFactory.getLogger(GameInstanceController.class);

    @Autowired
    IGameInstanceService gameInstanceService;

    @Autowired
    IInstanceMonsterService instanceMonsterService;

    @Autowired
    IInstanceMonsterSkillService instanceMonsterSkillService;

    @Autowired
    IGameInstanceConverter instanceConverter;

    @PostMapping(value="/list")
    public HttpResultDto<List<GameInstance>> list(@RequestBody GameInstanceDto gameInstanceDto){
        QueryWrapper queryWrapper = new QueryWrapper();
        if(gameInstanceDto.getMysticFlag()){
            queryWrapper.eq("mystic_flag",true);

        }
        if(gameInstanceDto.getRaidFlag()){
            queryWrapper.eq("raid_flag",true);
        }
        if(StringUtils.isNotBlank(gameInstanceDto.getInstanceVersion())){
            queryWrapper.eq("instance_version",gameInstanceDto.getInstanceVersion());
        }
        if(gameInstanceDto.getSeason() != 0){
            queryWrapper.eq("season",gameInstanceDto.getSeason());
        }
        List<GameInstance> instanceList = instanceMonsterService.list(queryWrapper);
        return HttpResultDto.success(instanceList);
    }

    @PostMapping(value="/detail")
    public HttpResultDto<GameInstanceDto> list(String instanceId){
        GameInstance instance = gameInstanceService.getById(instanceId);
        List<InstanceMonsterDto> monsterDtoList = instanceMonsterService.getListByInstanceId(instanceId);
        GameInstanceDto dto = instanceConverter.entityToDto(instance);
        dto.setMonsterList(monsterDtoList);
        return HttpResultDto.success(dto);
    }
}
